class Solution {
public:
    void dfs(TreeNode*& root, TreeNode* parent)
    {
        if (!root)
            return;
            
        dfs(root->left, root);
        dfs(root->right, root);
        
        
        if (!root->left && !root->right && root->val == 0)
        {
            //if (!parent)
                root = nullptr;
           // else if (root == parent->left)
               // parent->left = nullptr;
            //else
                //parent->right = nullptr;
            
            //delete root;
        }
    }
    TreeNode* pruneTree(TreeNode* root) {
        dfs(root, nullptr);
        
        return root;
    }
};

